package com.yunupmall.mapper.commoditymapper;

import cn.hutool.core.date.DateTime;
import com.yunupmall.api.fordentity.Kind;
import com.yunupmall.api.fordentity.Pay;
import com.yunupmall.api.po.OrderCounts;
import com.yunupmall.api.po.UserCounts;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface StatisticMapper {

    /**
     * 商品数据统计
     * @return
     */
    @Select("select count(*) as counts  from commodity where deflag=0")
    Integer  getOnCommtityCount();


    @Select("select count(*) as counts  from commodity where statics=0")
    Integer  getOnStaticCommtityCount();


    @Select("select count(*) as counts  from commodity where statics=1")
    Integer  getInStaticCommtityCount();

    /**
     * 会员数据统计
     */
    @Select("select count(*) as counts  from member where deflag=0")
    Integer  getMemberCount();


    @Select("select count(*) as counts  from member where create_time>=#{beginOfDay} and create_time<=#{endOfDay}")
    Integer  getDayMemberCount(@Param("beginOfDay") DateTime beginOfDay,@Param("endOfDay") DateTime endOfDay);


    @Select("select count(*) as counts  from member where create_time>=#{beginOfDay} and create_time<=#{endOfDay}")
    Integer  getOnDayMemberCount(@Param("beginOfDay") String beginOfDay,@Param("endOfDay") String endOfDay);

    /**
     * 订单数据
     */
    @Select("select count(*) as counts  from order_data where create_time>=#{beginOfDay} and create_time<=#{endOfDay}")
    Integer  getDayOrderCount(@Param("beginOfDay") DateTime beginOfDay,@Param("endOfDay") DateTime endOfDay);

    @Select("select * from pay where pay_time>=#{beginOfDay} and pay_time<=#{endOfDay} and m_id is null")
    List<Pay> getDayPay(@Param("beginOfDay") DateTime beginOfDay,@Param("endOfDay") DateTime endOfDay);


    @Select("select * from pay where pay_time>=#{beginOfDay} and pay_time<=#{endOfDay} and m_id is null")
    List<Pay> getOnDayPay(@Param("beginOfDay") String beginOfDay,@Param("endOfDay") String endOfDay);

    /**
     * 订单年度数据
     */
    @Select("SELECT DATE_FORMAT(create_time, '%m') AS month, COUNT(*) AS counts FROM order_data where YEAR(create_time)=#{date} GROUP BY month")
    List<OrderCounts> getYearOrderCounts(@Param("date") String Data);
    /**
     * 年度销售额
     */
    @Select("SELECT DATE_FORMAT(pay_time, '%m') AS month, SUM(total_amount) AS sale FROM pay where YEAR(pay_time)=#{date} and m_id is NULL GROUP BY month")
    List<OrderCounts> getYearSaleQuota(@Param("date") String Data);

    /**
     * 类别商品统计
     */
    @Select("select id,name from kind where deflag=0")
   List<Kind> getKindList();

    @Select("select count(*) from commodity where kind_id=#{kind_id} and  deflag=0")
    Integer getKindCommtityCount(@Param("kind_id") Integer id);
}
